<!doctype html>
<html lang="en" class="orange-theme">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover, user-scalable=no">
    <meta name="description" content="">
    <meta name="author" content="Maxartkiller">

    <title>首页 ·辰星中文网</title>

    <!-- iconfont CSS -->
    <link rel="stylesheet" href="/static/mobile/vendor/iconfont/iconfont.css">

    <!-- Roboto fonts CSS -->
    <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet">

    <!-- Bootstrap core CSS -->
    <link href="/static/mobile/vendor/bootstrap-4.3.1/css/bootstrap.min.css" rel="stylesheet">

    <!-- Swiper CSS -->
    <link href="/static/mobile/vendor/swiper/css/swiper.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="/static/mobile/css/style.css" rel="stylesheet">
</head>

<body>
<div class="wrapper article">
    <div class="header">
        <div class="row align-content-center no-gutters">
            <div class="col-auto">
                <a href="/mobile/book/bookInfo/id/{$book['id']}" class="btn btn-link text-dark"><i class="iconfont icon-back"></i></a>
            </div>
            <div class="col text-left header-title">{$chapter.name}</div>
            <div class="col-auto">
                <small class="text-secondary" style="line-height: 44px;padding-right: 15px;">{$chapter_index}/{$chapter_total}</small>
            </div>
        </div>
    </div>
    <article class="arti" style="text-indent: 2rem;">
        {if isset($is_auto) && $is_auto eq -1}
            {$content.content}
        <center>
            <span style="color:#ff2415;">本章共计{$chapter.size}字    {$money}书币</span><br>
            <button type="button" class="btn btn-sm btn-outline-success" id="chapter_buy">立即购买</button>
        </center>
        {else/}
            {$content.content}
        {/if}
    </article>

   <!-- <button type="button" class="btn btn-sm btn-outline-success" onclick="prevChapter();" style="margin-left:16px;">上一章</button>
    <button type="button" class="btn btn-sm btn-outline-success" onclick="nextChapter();" style="float:right; margin-right:20px;">下一章</button>-->

    <div class="d-flex justify-content-around position-fixed fixed-bottom bg-white pt-2 pb-2">
        <a href="/mobile/chapter/read/book_id/{$book['id']}/chapter_index/{$chapter_index-1}" type="button" class="btn btn-sm btn-outline-success" style="margin-left:16px;">上一章</a>
        <a href="/mobile/book/chapterList/book_id/{$book['id']}" type="button" class="btn btn-sm btn-outline-success">目录</a>
        <a href="/mobile/chapter/read/book_id/{$book['id']}/chapter_index/{$chapter_index+1}" type="button" class="btn btn-sm btn-outline-success" style="float:right; margin-right:20px;">下一章</a>
    </div>

</div>
<input type="hidden" name="member_id" value="{$member_id}">
<input type="hidden" name="book_id" value="{$book['id']}">
<input type="hidden" name="chapter_index" value="{$chapter_index-1}">
<input type="hidden" name="chapter_total" value="{$chapter_total}">
<input type="hidden" name="chapter_id" value="{$chapter['id']}">
{if isset($money)}
<input type="hidden" name="money" value="{$money}">
{else}
<input type="hidden" name="money" value="0">
{/if}
{if(isset($end))}
<input type="hidden" name="end" value="{$end}">
{else/}
<input type="hidden" name="end" value="0">
{/if}
<!-- jquery, popper and bootstrap js -->
<script src="/static/mobile/js/jquery-3.3.1.min.js"></script>
<script src="/static/mobile/vendor/bootstrap-4.3.1/js/bootstrap.min.js"></script>

<!-- Swiper js -->
<script src="/static/mobile/vendor/swiper/js/swiper.min.js"></script>

<!-- template custom js -->
<script src="/static/mobile/js/main.js"></script>

<!-- page level script -->

<script type="text/javascript" src="/static/layui/layui.js"></script>
<script>
    layui.use('layer', function(){
        var layer = layui.layer;
    $(document).ready(function() {
        let end = $('input[name="end"]').val();
        let book_id = $('input[name="book_id"]').val();
        var member_id = $('input[name="member_id"]').val();
        var money = $('input[name="money"]').val();
        //右上角关闭回调
        let chapter_index = $('input[name="chapter_index"]').val();
        if(end == 1){
            /*layer.open({
                title: '辰星中文网提示'
                ,content: '没有更多章节了!!!'
            });*/
            layer.msg('没有更多章节了!!!');
            // window.location.href="/mobile/book/bookInfo/id/"+book_id;
        }

        //没有登录
        if(member_id == -1){
            layer.open({
                title: '辰星中文网提示:'
                ,content: '您还没有登陆，请先登录。'
                ,btn: ['立即登录', '看看其他']
                ,yes: function(index, layero){
                    //按钮【按钮一】的回调
                    window.location.href="/mobile/login/login";
                }
                ,btn2: function(index, layero){
                    //按钮【按钮二】的回调
                    window.location.href="/mobile/index/index"
                    //return false 开启该代码可禁止点击该按钮关闭
                }
                ,cancel: function(){
                    //右上角关闭回调
                    let chapter_index = $('input[name="chapter_index"]').val();
                    let book_id = $('input[name="book_id"]').val();
                    window.location.href = '/mobile/chapter/read/book_id/'+book_id+'/chapter_index/'+chapter_index;
                    //return false 开启该代码可禁止点击该按钮关闭
                }
            });
        }

        //书币不足
        if(money == -1){
            layer.open({
                title: '辰星中文网提示:'
                ,content: '书币不足立即充值'
                ,btn: ['立即充值', '看看其他']
                ,yes: function(index, layero){
                    //按钮【按钮一】的回调
                    window.location.href="/mobile/rechange/pay";
                }
                ,btn2: function(index, layero){
                    //按钮【按钮二】的回调
                    window.location.href="/mobile/index/index"
                    //return false 开启该代码可禁止点击该按钮关闭
                }
                ,cancel: function(){
                    window.location.href = '/mobile/chapter/read/book_id/'+book_id+'/chapter_index/'+chapter_index;
                    //return false 开启该代码可禁止点击该按钮关闭
                }
            });
        }
    });
    $('#chapter_buy').click(function(){
        var chapter_id = $('input[name="chapter_id"]').val();
        var chapter_index = $('input[name="chapter_index"]').val();
        // chapter_index+=1;
        // alert();return false;
        var book_id = $('input[name="book_id"]').val();
        var money = $('input[name="money"]').val();
        $.post('/mobile/chapter/chapterBuy',{chapter_id:chapter_id,money:money},function(data){
           if(data.state == 200){
               layer.msg(data.msg);
               window.location.href='/mobile/chapter/read/book_id/'+book_id+'/chapter_index/'+(Number(chapter_index)+1);
           }else{
               layer.msg(data.msg);
           }
        });
    });
    });
</script>

<script>
    /*function prevChapter()
    {
        let chapter_index = $('input[name="chapter_index"]').val()-1;
        let book_id = $('input[name="book_id"]').val();
        window.location.href = '/mobile/chapter/read/book_id/'+book_id+'/chapter_index/'+chapter_index;
    }
    function nextChapter()
    {
        let chapter_index = $('input[name="chapter_index"]').val()+1;
        let book_id = $('input[name="book_id"]').val();
        window.location.href = '/mobile/chapter/read/book_id/'+book_id+'/chapter_index/'+chapter_index;
    }*/
</script>
</body>

</html>
